package com.chrray.position.util.request;

import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

public class RequestUtils {

	private RequestUtils(){}

	public static String getToken(HttpServletRequest request) {
		Cookie[] cookies = request.getCookies();
		String token = null;
		if(cookies!=null && cookies.length!=0) {
			for (Cookie cookie : cookies) {
				String name = cookie.getName();
				if("token".equals(name)) {
					token = cookie.getValue();
				}
			}
		}

		String headerToken = request.getHeader("token");
		if(StringUtils.isNotBlank(headerToken)) {
			token = headerToken;
		}
		return token;
	}

}
